define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'autocomplete'], function ($, undefined, Backend, Table, Form, Template, Autocomplete) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: '/sys/process/data',
                    add_url: '/sys/process/add?craft_id=' + craft.id,
                    edit_url: '/sys/process/edit',
                    del_url: '/sys/process/del',
                    multi_url: 'data/multi.json',
                    "table": 'page',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                columns: [
                    [
                        {field: 'aaa', checkbox: true},
                        {field: 'id', title: __('ID'), operate: false},
                        {
                            field: 'process_line_ids', title: __('下面生产线的数量'), formatter: function (value, row, index) {
                                if (value) {
                                    return '<span class="btn btn-auth bg-blue btn-xs btn-detail">点击查看' + value.split(',').length + '条生产线详情</span>';
                                } else {
                                    return "无";
                                }
                            }, events: $.extend({
                                'click .btn-auth': function (e, value, row, index) {
                                    Backend.api.open("/sys/processLine/index?id=" + value, "给<code>" + row.title + "</code>配置生产线");
                                }
                            }, Table.api.events.operate), operate: false

                        },
                        {field: 'craft_id', title: __('父id'), operate: 'LIKE %...%', placeholder: '模糊搜索', style: 'width:200px'},
                        {field: 'title', title: __('名称'), operate: 'LIKE %...%', placeholder: '模糊搜索', style: 'width:200px'},
                        {field: 'content', title: __('工序描述'), operate: 'LIKE %...%', placeholder: '模糊搜索', style: 'width:200px'},
                        {
                            field: 'status', title: __("状态"), operate: false, formatter: function (value, row, index) {
                                if (value == 0) {
                                    return '<span class="text-success"><i class="fa fa-circle"></i> 启用</span>';
                                } else {
                                    return '<span class="text-red"><i class="fa fa-circle"></i> 禁用</span>';
                                }

                            }
                        },
                        {field: 'create_time', title: __('创建时间'), operate: false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('更新时间'), operate: false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'opearte',
                            title: __('操作'),
                            operate: false,
                            formatter: function (value, row, index) {
                                return '<span class="btn btn-auth bg-blue btn-xs btn-detail">配置已有的生产线</span>' + Table.api.formatter.operate(value, row, index, $("#table"));
                            },
                            events: $.extend({
                                'click .btn-auth': function (e, value, row, index) {
                                    Backend.api.open("/sys/process/config?process_id=" + row['id'], "给" + row.title + "配置生产线");
                                }
                            }, Table.api.events.operate)
                        },
                    ]
                ],
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: true,
                exportDataType: 'selected'
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }

    };
    return Controller;

});